﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.Serialization;
using System.Xml.Serialization;
using System.Diagnostics;

namespace FileTesterFormat
{
    public class RulesStatic
    {
        public static void Create()
        {
            var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Rules.xml");
            if (!File.Exists(filePath))
            {
                Rules allRules = new Rules();
                allRules.AddRange(GetDemo1Rule());

                using (var filestream = new StreamWriter(filePath))
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(Rules));
                    serializer.Serialize(filestream, allRules);
                }

            }
        }

        private static Rules GetDemo1Rule()
        {
            var rule = new Rules();
            rule.Add(new RulesDescription()
            {
                Title = "Demo 1",
                RuleItems = new List<RuleItem>
                {
                    new RuleItem { Description = "Code", StartIndex = 0, StopIndex = 6}, 
                    new RuleItem { Description = "Year", StartIndex = 7, StopIndex = 10}, 
                    new RuleItem { Description = "Month", StartIndex = 11, StopIndex = 12}, 
                    new RuleItem { Description = "Day", StartIndex = 13, StopIndex = 14}, 
                    new RuleItem { Description = "Spaces", StartIndex = 15, StopIndex = 20}, 
                }
            });

            return rule;
        }
    }
}
